﻿@model IEnumerable<WZGL.Models.ProInfo>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<form method="get" class="form-inline text-center" style="margin:10px">
    物资类型:@Html.DropDownList("Type", null, new { @class = "form-control" })
    物资名称:<input type="text" name="content" class="form-control" placeholder="请输入物资名称" />
    <input type="submit" value="查询" class="btn btn-primary" />
    @Html.ActionLink("添加物资", "Create", null, new { @class = "btn btn-primary" })
</form>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.IsDestroy)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Unit)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Description)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Type)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.ID)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.AddTime)
            </td>
            <td>
                @(item.IsDestroy==true? "已报废" : "未报废")
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Unit)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Price)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Description)
            </td>
            <td>
                @if (item.Type == 1)
                {
                    @:原料
                }
                else if (item.Type == 2)
                {
                    @:工具
                }
                else if (item.Type == 3)
                {
                    @:配件
                }
                else
                {
                    @:设备
                }
            </td>
            <td>
                @if (item.IsDestroy == false)
                {
                    <a href="#" data-des="@item.ID">报废</a>
                }
            </td>
        </tr>
    }
    @if (Model.Count() < 1)
    {
        <tr>
            <td colspan="9">
                不好意思，无相关物资信息！
            </td>
        </tr>
    }
</table>

@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-des]").click(function () {
                var  $this = $(this);
                var id = $this.attr("data-des");
                if (!confirm("你确定要报废编号为" + id + "的物资？")) return;
                $.post("@Url.Content("~/Home/Edit")", { id: id }, function (res) {
                    if (res==true) {
                        alert("此物已报废!");
                        location.reload();
                    }
                })

            })
        })
    </script>
}